package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.model.entity.TeamListEntity;
import com.runen.infinitemovement.tool.CommonUtil;
import com.runen.infinitemovement.tool.GlideUtils;
import com.runen.infinitemovement.widget.imageview.RoundedCornersImage;

/**
 * Create by LiaoDuanHong
 * Create on 2021/02/27 17:46
 */
public class CheckTeamAdapter extends BaseQuickAdapter<TeamListEntity.DataBean, BaseViewHolder> {
    private Context context;
    private boolean isTeamGroup;

    public OnJoinClickListener getOnJoinClickListener() {
        return onJoinClickListener;
    }

    public void setOnJoinClickListener(OnJoinClickListener onJoinClickListener) {
        this.onJoinClickListener = onJoinClickListener;
    }

    private OnJoinClickListener onJoinClickListener;

    public CheckTeamAdapter(Context context, boolean isTeamGroup) {
        super(R.layout.item_check_team);
        this.context = context;
        this.isTeamGroup = isTeamGroup;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, TeamListEntity.DataBean item) {
        String number_info = "队伍:%s/" + item.limitNumber + "人";
        baseViewHolder.setText(R.id.tv_number_info, String.format(number_info, item.count));
        RoundedCornersImage cornersImage = baseViewHolder.getView(R.id.rci_header);
        TextView tv_join = baseViewHolder.getView(R.id.tv_join);
        if (TextUtils.isEmpty(item.logo)) {
            GlideUtils.loadImage(context, R.mipmap.ico_person_head, cornersImage);
        } else {
            GlideUtils.loadImage(context, item.logo, cornersImage);
        }

        if (isTeamGroup) {
            tv_join.setVisibility(View.GONE);
        } else
            tv_join.setVisibility(View.VISIBLE);


        baseViewHolder.setText(R.id.tv_team_name, item.teamName);
        String join = "确定加入“%s”？";
        if (item.count >= item.limitNumber) {
            tv_join.setBackground(null);
            tv_join.setTextColor(CommonUtil.getColor(R.color.color_A5A6AB));
            tv_join.setEnabled(false);
            tv_join.setText("已满");
        } else {
            tv_join.setBackground(CommonUtil.getDrawable(R.drawable.bg_fff63e5a_cr_4dp));
            tv_join.setTextColor(CommonUtil.getColor(R.color.color_FFF63E5A));
            tv_join.setEnabled(true);
            tv_join.setText("加入");
        }

        tv_join.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (onJoinClickListener != null) {
                    onJoinClickListener.onClick(item.teamId, String.format(join, item.teamName));
                }
            }
        });


    }


    public interface OnJoinClickListener {
        void onClick(String teamId, String teamName);
    }
}
